package com.yuehuanghun.admin.core.service.impl;

import org.springframework.stereotype.Service;

import com.yuehuanghun.admin.core.config.UserConstants;
import com.yuehuanghun.admin.core.domain.SysPost;
import com.yuehuanghun.admin.core.mapper.SysPostMapper;
import com.yuehuanghun.admin.core.service.ISysPostService;
import com.yuehuanghun.framework.util.StringUtils;
import com.yuehuanghun.mybatis.milu.ext.BaseServiceImpl;

/**
 * 岗位信息 服务层处理
 * 
 * @author yadmin
 */
@Service
public class SysPostServiceImpl extends BaseServiceImpl<SysPost, Long, SysPostMapper> implements ISysPostService {

	/**
	 * 校验岗位名称是否唯一
	 * 
	 * @param post 岗位信息
	 * @return 结果
	 */
	@Override
	public String checkPostNameUnique(SysPost post) {
		Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
		SysPost info = domainMapper.findFirstByPostName(post.getPostName());
		if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
			return UserConstants.NOT_UNIQUE;
		}
		return UserConstants.UNIQUE;
	}

	/**
	 * 校验岗位编码是否唯一
	 * 
	 * @param post 岗位信息
	 * @return 结果
	 */
	@Override
	public String checkPostCodeUnique(SysPost post) {
		Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
		SysPost info = domainMapper.findFirstByPostCode(post.getPostCode());
		if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
			return UserConstants.NOT_UNIQUE;
		}
		return UserConstants.UNIQUE;
	}

}
